﻿
<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ page import="com.cxx.purchasecharge.component.utils.ComponentConstants"%>

	<style type="text/css">
		#dlg-provider input,#dlg-provider select {
			width: 150px;
		}
		
		#dlg-provider #fm-provider div {
			float: left;
			width: 300px;
		}
		
		#dlg-provider #fm-provider div label {
			width: 80px;
		}
	</style>
	<script type="text/javascript">
		var providerGridDetailFormatter = function(index,row){
			return '<div class="ddv-provider" style="padding:5px 0"></div>';
		}
		
		var providerGridExpandRow = function(index,row){
			var ddv = $(this).datagrid('getRowDetail',index).find('div.ddv-provider');
			var trade = (null != row.tradeBean ? row.tradeBean.name : '');
			ddv.panel({
				height:65,
				border:false,
				cache:false,
				content:"<style type='text/css'>.dv-table-provider td{border:0;}.dv-label-provider{font-weight:normal;color:#15428B;width:10%;}.dv-nonlabel-provider{width:23%;}</style>" + 
				"<table class='dv-table-provider' border='0' style='width:100%;'>" + 
				"<tr><td class='dv-label-provider'>公司名称:</td><td class='dv-nonlabel-provider'>" + row.companyName + 
				"</td><td class='dv-label-provider'>地址:</td><td class='dv-nonlabel-provider'>" + row.address + 
				"</td><td class='dv-label-provider'>简介:</td><td class='dv-nonlabel-provider'>" + row.companyIntroduction + 
				"</td></tr>" + "<tr><td class='dv-label-provider'>邮编:</td><td class='dv-nonlabel-provider'>" + row.zipCode + 
				"</td><td class='dv-label-provider'>规模:</td><td class='dv-nonlabel-provider'>" + row.scale + 
				"</td><td class='dv-label-provider'>行业:</td><td class='dv-nonlabel-provider'>" + trade + "</td></tr>" + 
				"<tr><td class='dv-label-provider'>网址:</td><td class='dv-nonlabel-provider'>" + row.webSite + 
				"</td><td class='dv-label-provider'>注册日期:</td><td class='dv-nonlabel-provider'>" + row.regDate + 
				"</td><td class='dv-label-provider'>注册资金:</td><td class='dv-nonlabel-provider'>" + row.regFund + 
				"</td></tr>" + "</table>",
				onLoad:function(){
					$('#dg-provider').datagrid('fixDetailRowHeight',index);
				}
			});
			$('#dg-provider').datagrid('fixDetailRowHeight',index);
		}
	
		var newProviderCallback = function() 
		{
			$('#fm-provider input.easyui-combobox').combobox('reload');
			$('#fm-provider #userSignedTo').val('${sessionScope.login_user.userId}');
			$('#fm-provider #signUserFullName').val('${sessionScope.login_user.fullName}');
			$('#dlg-provider #fm-provider #sharable').combobox('setValue', false);
			$('#dlg-provider #fm-provider #sharable').combobox('setText', '不可共享');
		}
		var editProviderCallback = function () 
		{
			$('#fm-provider input.easyui-combobox').combobox('reload');
			var provider = $('#dg-provider').datagrid('getSelected');
			//$('#dlg-provider #fm-provider #contactId').val(provider.contactBean.id);
			//$('#dlg-provider #fm-provider #contactName').val(provider.contactBean.name);
			if(provider.levelBean) 
			{
				$('#dlg-provider #fm-provider #level').combobox('setValue', provider.levelBean.id);
			}
			if(provider.sourceBean) 
			{
				$('#dlg-provider #fm-provider #source').combobox('setValue', provider.sourceBean.id);
			}
			if(provider.statusBean) 
			{
				$('#dlg-provider #fm-provider #status').combobox('setValue', provider.statusBean.id);
			}
			if(provider.tradeBean) 
			{
				$('#dlg-provider #fm-provider #trade').combobox('setValue', provider.tradeBean.id);
			}
			if(provider.sharable) 
			{
				$('#dlg-provider #fm-provider #sharable').combobox('setValue', provider.sharable);
				$('#dlg-provider #fm-provider #sharable').combobox('setText', '可共享');
			}
			else 
			{
				$('#dlg-provider #fm-provider #sharable').combobox('setValue', provider.sharable);
				$('#dlg-provider #fm-provider #sharable').combobox('setText', '不可共享');
			}
		}
		var viewProviderPaymentRecord = function () 
		{
			var row = $('#dg-provider').datagrid('getSelected');
			if (row) {
				$('#dlg-view-provider-payment').dialog('open').dialog('setTitle', '查看' + row.shortName + '的付款记录');
				loadGridData ('#dg-provider-payment', '<c:url value='/provider/getPaymentByProvider.html' />', {providerId : row.id});
			}
		}
		/*var addProviderPaymentCallback = function () 
		{
			var row = $('#dg-provider').datagrid('getSelected');
			if (row) {
				$('#dlg-add-provider-payment #fm-add-provider-payment #customerId').val (row.id);
			}
		}*/
		
		var onClickProviderRow = function (rowIndex, rowData) 
		{
			$('#toolbar-provider #btn-editProvider').linkbutton('enable');
			//$('#toolbar-provider #btn-deleteProvider').linkbutton('enable');
			//$('#toolbar-provider #btn-receivePay').linkbutton('enable');
			$('#toolbar-provider #btn-viewPay').linkbutton('enable');
			$('#toolbar-provider #btn-bindContact').linkbutton('enable');
			$('#toolbar-provider #btn-viewContact').linkbutton('enable');
		}
		var onLoadProviderSuccess = function(data) 
		{
			$('#toolbar-provider #btn-editProvider').linkbutton('disable');
			$('#toolbar-provider #btn-deleteProvider').linkbutton('disable');
			//$('#toolbar-provider #btn-receivePay').linkbutton('disable');
			$('#toolbar-provider #btn-viewPay').linkbutton('disable');
			$('#toolbar-provider #btn-bindContact').linkbutton('disable');
			$('#toolbar-provider #btn-viewContact').linkbutton('disable');
		}
		function doSearchProvider(value) {
			$('#dg-provider').datagrid('load', {
				searchKey : value
			});
		}
		var onCheckAllProvider = function(rows) 
		{
			$('#toolbar-provider #btn-deleteProvider').linkbutton('enable');
		}
		var onUnCheckProvider = function(rowIndex,rowData) 
		{
			var rows = $('#dg-provider').datagrid('getChecked');
			if (rows.length == 0) {
				$('#toolbar-provider #btn-deleteProvider').linkbutton('disable');
			}
		}
	</script>

<div style="width: 100%; height: 450px;">
	<table id="dg-provider" title="供应商管理" class="easyui-datagrid"
		url="<c:url value='/provider/getAll.html' />"
		toolbar="#toolbar-provider" pagination="true" rownumbers="true"
		singleSelect="true" checkOnSelect="true" selectOnCheck="false" showFooter="true" 
		data-options="fitColumns:true, sortName:'dealMoney', sortOrder:'desc', view:detailview, detailFormatter:providerGridDetailFormatter,  onExpandRow:providerGridExpandRow, fit:true, onClickRow:onClickProviderRow, onLoadSuccess:onLoadProviderSuccess, onCheckAll:onCheckAllProvider, onUncheckAll:onUnCheckProvider, onCheck:onCheckAllProvider, onUncheck:onUnCheckProvider">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
				<th data-options="field:'id',hidden:true"></th>
				<th field="shortName" width="100" sortable="true"><spring:message code="customer.shortName" /></th>
				<!-- 				<th field="contactId" hidden="true"></th> -->
				<th field="contactName" width="100" data-options="formatter:contactNameFormatter, styler:cellStyler_userRole">联系人</th>
				<!--<th field="typeCode" width="100"><spring:message code="customer.type" /></th>-->
				<th field="email" width="100" sortable="true"><spring:message code="customer.email" /></th>
				<th field="fixedPhone" width="100" sortable="true"><spring:message code="customer.fixedPhone" /></th>
				<th field="source" width="100" data-options="formatter:sourceFormatter">
					<spring:message code="customer.source" /></th>
				<%-- 				<th field="sourceBean.id" width="100" hidden="true" data-options="formatter:sourceIdFormatter"><spring:message code="customer.source" /></th> --%>
				<th field="level" width="100" data-options="formatter:levelFormatter">
					<spring:message code="customer.level" /></th>
				<%-- 				<th field="levelBean.id" width="100" hidden="true" data-options="formatter:levelIdFormatter"><spring:message code="customer.level" /></th> --%>
				<th field="status" width="100" data-options="formatter:statusFormatter">
					<spring:message code="customer.status" /></th>
				<%-- 				<th field="statusBean.id" width="100" hidden="true" data-options="formatter:statusIdFormatter"><spring:message code="customer.status" /></th> --%>
				<th field="goodsIntention" width="100" sortable="true">
					<spring:message code="customer.goodsIntention" /></th>
				<th field="userSignedTo" width="100" sortable="true"><spring:message code="customer.signUserId" /></th>
				<th field="sharable" width="100" sortable="true" data-options="formatter:cellFormatter_customerSharable">
					<spring:message code="customer.isSharable" /></th>
				<th field="dealMoney" width="100" sortable="true" data-options="styler:dealMoney_styler">应付款</th>

				<!-- put into detail view panel -->
				<th field="companyName" width="100" hidden="true"><spring:message code="customer.companyName" /></th>
				<th field="address" width="100" hidden="true"><spring:message code="customer.address" /></th>
				<th field="companyIntroduction" width="100" hidden="true"><spring:message code="customer.companyIntroduction" /></th>
				<th field="zipCode" width="100" hidden="true"><spring:message code="customer.zipCode" /></th>
				<th field="scale" width="100" hidden="true"><spring:message code="customer.scale" /></th>
				<th field="trade" width="100" hidden="true" data-options="formatter:tradeFormatter">
					<spring:message code="customer.trade" /></th>
				<%-- 				<th field="tradeBean.id" width="100" hidden="true" data-options="formatter:tradeIdFormatter"><spring:message code="customer.trade" /></th> --%>
				<th field="webSite" width="100" hidden="true"><spring:message code="customer.webSite" /></th>
				<th field="regDate" width="100" hidden="true"><spring:message code="customer.registerDate" /></th>
				<th field="regFund" width="100" hidden="true"><spring:message code="customer.registerFund" /></th>
				<th field="region" width="100" hidden="true"><spring:message code="customer.region" /></th>
			</tr>
		</thead>
	</table>
</div>
<div id="toolbar-provider">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true"
		onclick="newModel('#dlg-provider', '新增供应商', '#fm-provider', '<c:url value='/provider/newProvider.html' />', newProviderCallback)"
		title="新增供应商">新增供应商</a> 
	<a id="btn-editProvider" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" disabled="true" 
		onclick="editModel('#dg-provider', '#dlg-provider', '编辑供应商', '#fm-provider', '<c:url value='/provider/updateProvider.html' />', editProviderCallback)"
		title="<spring:message code="selectOneRow" />编辑供应商">编辑供应商</a> 
	<a id="btn-deleteProvider" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" disabled="true" 
		onclick="destroyMultipleModel('#dg-provider', '<spring:message code="customer" />', '<c:url value='/provider/delProvider.html' />')"
		title="<spring:message code="checkOneOrMultiple" />删除供应商">删除供应商</a> 
	<!--<a id="btn-receivePay" href="javascript:void(0)" class="easyui-linkbutton" plain="true" disabled="true" 
		onclick="editModel('#dg-provider', '#dlg-add-provider-payment', '付款', '#fm-add-provider-payment', '<c:url value='/provider/updatePaid.html' />', addProviderPaymentCallback)"
		title="">付款</a> -->
	<a id="btn-viewPay" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" 
		iconCls="icon-search" plain="true" onclick="viewProviderPaymentRecord()" title="<spring:message code="selectOneRow" />查看供应商付款记录">查看付款记录</a>
	<!--<a id="btn-bindContact" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" 
		plain="true" onclick="" title="">绑定联系人</a>
	<a id="btn-viewContact" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" 
		plain="true" onclick="" title="">查看联系人</a>-->
	<span style="float: right; margin-right: 5px"> 
		<input class="easyui-searchbox"
			data-options="prompt:'<spring:message code="pleaseInputValue" />',searcher:doSearchProvider" style="width: 300px" />
	</span>
</div>

<div id="dlg-provider" class="easyui-dialog"
	style="width: 750px; height: 390px; padding: 5px" closed="true"
	buttons="#dlg-buttons-provider" data-options="modal:true">
	<div id="" style="padding: 0px 20px">
		<form id="fm-provider" class="fm" method="post" novalidate>
			<div class="fitem divHidden">
				<input id="custoId" name="id" value="0">
			</div>
			<div class="fitem">
				<label><spring:message code="customer.shortName" />:</label> 
				<input name="shortName" class="easyui-validatebox" required="true"
					validType="myRemote['<c:url value='/provider/checkExist.html' />', 'name', '#custoId']">
			</div>

			<div class="fitem">
				<label><spring:message code="customer.companyName" />:</label> 
				<input name="companyName" class="easyui-validatebox">
			</div>
			<div class="fitem">
				<label><spring:message code="customer.companyIntroduction" />:</label>
				<input name="companyIntroduction" class="easyui-validatebox">
			</div>
			<div class="fitem">
				<label><spring:message code="customer.address" />:</label> 
				<input name="address" class="easyui-validatebox">
			</div>
			<div class="fitem">
				<label><spring:message code="customer.zipCode" />:</label> 
				<input name="zipCode" class="easyui-numberbox" style="width:156px">
			</div>
			<div class="fitem">
				<label><spring:message code="customer.email" />:</label> 
				<input name="email" class="easyui-validatebox">
			</div>
			<div class="fitem">
				<label><spring:message code="customer.fixedPhone" />:</label> 
				<input name="fixedPhone" class="easyui-validatebox" validType="phoneCheck" />
			</div>
			<div class="fitem">
				<label><spring:message code="customer.scale" />:</label> 
				<input name="scale" class="easyui-validatebox">
			</div>
			<div class="fitem">
				<label><spring:message code="customer.goodsIntention" />:</label> 
				<input name="goodsIntention" class="easyui-validatebox" />
			</div>
			<div class="fitem">
				<label><spring:message code="customer.webSite" />:</label> 
				<input name="webSite" class="easyui-validatebox">
			</div>

			<div class="fitem">
				<label><spring:message code="customer.region" />:</label> 
				<input name="region" class="easyui-validatebox" />
			</div>
			<div class="fitem">
				<label><spring:message code="customer.isSharable" />:</label> 
				<select id="sharable" name="sharable" class="easyui-combobox" panelHeight="auto" 
					style="width: 150px" editable="false" required="true" data-options="">
					<option value="true" selected="selected">
						<spring:message code="customer.option.enSharable" />
					</option>
					<option value="false">
						<spring:message code="customer.option.unSharable" />
					</option>
				</select>
			</div>
			<div class="fitem">
				<label><spring:message code="customer.level" />:</label> 
				<input id="level" name="levelBean.id" class="easyui-combobox"
					style="width: 150px" editable="false" panelHeight="auto" 
					data-options="valueField:'id',textField:'name',method:'post',url:'', onShowPanel:onShowCustomerLevel">
			</div>
			<div class="fitem">
				<label><spring:message code="customer.status" />:</label> 
				<input id="status" name="statusBean.id" class="easyui-combobox"
					style="width: 150px" editable="false" panelHeight="auto" 
					data-options="valueField:'id',textField:'name',method:'post',url:'', onShowPanel:onShowCustomerStatus">
			</div>
			<div class="fitem">
				<label><spring:message code="customer.trade" />:</label> 
				<input id="trade" name="tradeBean.id" class="easyui-combobox"
					style="width: 150px" editable="false" panelHeight="auto" 
					data-options="valueField:'id',textField:'name',method:'post',url:'', onShowPanel:onShowCustomerTrade">
			</div>
			<div class="fitem">
				<label><spring:message code="customer.source" />:</label> 
				<input id="source" name="sourceBean.id" class="easyui-combobox"
					style="width: 150px" editable="false" panelHeight="auto" 
					data-options="valueField:'id',textField:'name',method:'post',url:'', onShowPanel:onShowCustomerSource">
			</div>
			<div class="fitem divHidden">
				<input id="userSignedTo" name="userSignedTo" class="easyui-validatebox"
					readonly="readonly" />
			</div>
			<div class="fitem">
				<label><spring:message code="customer.signUserId" />:</label> 
				<input id="signUserFullName" name="signUserFullName" class="easyui-validatebox"
					readonly="readonly" />
			</div>
			<div class="fitem">
				<label><spring:message code="customer.registerFund" />:</label> 
				<input name="regFund" class="easyui-numberbox" data-options="precision:1, min:1" style="width:156px">
			</div>
			<div class="fitem">
				<label><spring:message code="customer.registerDate" />:</label> 
				<input name="regDate" class="easyui-datebox" editable="false" style="width: 150px"
					onkeyup="if(event.keyCode == 13) {$('#save-provider').click()}">
			</div>
		</form>
	</div>
</div>
<div id="dlg-buttons-provider">
	<a id="save-provider" href="javascript:void(0)"
		class="easyui-linkbutton" iconCls="icon-ok"
		onclick="saveModel('#dg-provider', '#dlg-provider', '#fm-provider')">
		<spring:message code="save" /></a> 
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel"
		onclick="javascript:$('#dlg-provider').dialog('close')">
		<spring:message code="cancel" /></a>
</div>

<!-- 查看付款记录弹出框 -->
<div id="dlg-view-provider-payment" class="easyui-dialog"
	style="width: 750px; height: 390px; padding: 5px;" closed="true"
	buttons="#dlg-buttons-view-provider-payment" data-options="modal:true">
	<div id="" style="margin-top: 5px;">
		<table id="dg-provider-payment" class="easyui-datagrid"
			style="width: 700px; height: auto" url="" rownumbers="true"
			singleSelect="true" fitColumns="true">
			<thead>
				<tr>
					<th data-options="field:'id',hidden:true"></th>
					<th field="<%=ComponentConstants.PAY_DATE%>" width="100"><spring:message code="order.payDate" /></th>
					<th field="operator" width="50">操作者</th>
					<th field="orderId" width="100">订单号</th>
					<th field="<%=ComponentConstants.PAID%>" width="50" data-options="styler:dealMoney_styler">应付额</th>
					<th field="allUnPaid" width="50">未付总额</th>
					<th field="comment" width="150">备注</th>
				</tr>
			</thead>
		</table>
	</div>
</div>
<div id="dlg-buttons-view-provider-payment">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel"
		onclick="javascript:$('#dlg-view-provider-payment').dialog('close')">关闭</a>
</div>
<!-- 查看付款记录弹出框 -->